/config,nproc,4
/config,nres,20000
/FILNAME, Al6061
/PREP7
/title, sequentially coupled analysis with heat flux on top surface
Antype,trans

ET,1,SOLID70
MP,DENS,1,2700
MP,KXX,1,167
MPTEMP,,0,40,125,225,325,425,575,645
MPDATA,C,1,,910,950,1000,1050,1100,1150,1270,1310


length=0.24
tlength=0.18
width=0.05
thick=0.006
xstart=0.03
nthke=4
smesize=0.0015

ncopy=NINT(length/(4*smesize))
block,,4*smesize,,thick,,10*smesize
block,,4*smesize,,thick,10*smesize,12*smesize
block,,4*smesize,,thick,12*smesize,14*smesize
block,,4*smesize,,thick,14*smesize,width
nummrg,all
numcmp,all
lesize,1,,,nthke
MSHAPE,0,3D
MSHKEY,1
esize,smesize
vMESH,1
lesize,15,,,2,
lesize,13,,,2,
lesize,14,,,4,
lesize,16,,,4,
lesize,17,,,1,
lesize,20,,,1,
lesize,18,,,1,
lesize,19,,,1,
vMESH,2
lesize,22,,,2,
lesize,24,,,2,
lesize,21,,,2,
lesize,23,,,2,
lesize,25,,,1,
lesize,26,,,1,
lesize,27,,,1,
lesize,28,,,1,
vmesh,3
lesize,36,,,9
vmesh,4
VGEN,ncopy, all,,,4*smesize,,,,,
nummrg,all
FINISH

/SOLU 
tunif,25 
allsel
nsel,s,loc,y,
SF,all,CONV,1000,20 
allsel
nsel,s,loc,x,0
nsel,a,loc,x,length
nsel,a,loc,z,width
nsel,a,loc,y,thick
SF,all,CONV,15,20
allsel


kbc,1 
time,0.001
DELTIM,0.001 
solve

AUTOTS,ON
ddept=0.006
ddtime=0.5
dvel=0.0002
dinc=ddtime*dvel
dtime=0.2
dtotal=30
dweltime=10
ndwel=dweltime/dtime
dnloct=dtotal/ddtime 
tvel=0.00233                      !welding speed
xinc=dtime*tvel
nloct=NINT(tlength/xinc)
rshoulder=0.012
rprobe=0.003
phinput=220
nheatgen=phinput/(dnloct*dinc*3.14*rprobe*rprobe)
ehfulx=220*8.7

    nsel,s,loc,y,thick
    nsel,r,loc,z,-rprobe,rprobe
    nsel,r,loc,x,-rprobe,rprobe
    ESLN,s,
    SFEDELE,all,4,CONV
allsel
    nsel,s,loc,z,-(rshoulder+smesize),(rshoulder+smesize)
    *get,numnode,node,0,count   !number of nodes in the selected set
    *get,lnnum,node,0,num,min    !loest node number in the selected set
    *dim,nodenumber,ARRAY,numnode 
    *dim,nodenumbertop,ARRAY,numnode 
    *dim,nodenumber2,ARRAY,numnode 
    *dim,nodenumber3,ARRAY,numnode 
    *dim,nodehflux,ARRAY,numnode
    *dim,emnumber,ARRAY,numnode 
    allsel
! plunge
*do,ka,1,dnloct,1
    x0=xstart   !start point
    z0=0
    nsel,s,loc,z,-(rshoulder+smesize),(rshoulder+smesize)

     nnum=lnnum
     kd=0
    *do,kb,1,numnode
       *get,xlocation,node,nnum,loc,x
       *get,zlocation,node,nnum,loc,z
       *get,ylocation,node,nnum,loc,y
        rd=SQRT((xlocation-x0)**2+(zlocation-z0)**2)

          *if,rd,le,rprobe,THEN
            *if,ylocation,ge,(thick-ka*dinc),then
	            kd=kd+1
	            nodenumber2(kd)=nnum
 	            bf,nnum,HGEN,nheatgen
             *endif
          *endif
       *get,nexthn,node,nnum,nxth
        nnum=nexthn
     *enddo
    allsel
        step2time=ka*ddtime+0.001
        time,step2time
        DELTIM,ddtime
        KBC,1 
        outres,BASIC,LAST       
        solve
/solu
    *do,ke,1,kd
     bfdele,nodenumber2(ke),HGEN
    *enddo
*enddo
allsel



*do,i,1,(nloct+ndwel),1
        *if,i,le,ndwel,then
           x0=xstart
        *else
          x0=xstart+(i-ndwel)*xinc   !start point
        *endif
           z0=0
    nsel,s,loc,z,-(rshoulder+smesize),(rshoulder+smesize)

     nnum=lnnum
     jj=0
     kk=0
     tt=0
    *do,ia,1,numnode
       *get,xlocation,node,nnum,loc,x
       *get,zlocation,node,nnum,loc,z
       *get,ylocation,node,nnum,loc,y
        rd=SQRT((xlocation-x0)**2+(zlocation-z0)**2)

          *if,rd,le,rshoulder,and,rd,gt,rprobe,THEN
            *if,ylocation,eq,thick,then
            jj=jj+1
            nodenumber(jj)=nnum
            nodehflux(jj)=3*ehfulx*rd/(2*3.1416*(rshoulder**3-rprobe**3))
            *endif
          *endif
          *if,rd,le,rshoulder,THEN
            *if,ylocation,eq,thick,then
            tt=tt+1
            nodenumber3(tt)=nnum
            *endif
          *endif
          *if,rd,le,rprobe,then
            kk=kk+1
            nodenumber2(kk)=nnum
             bf,nnum,HGEN,nheatgen
          *endif
       *get,nexthn,node,nnum,nxth
        nnum=nexthn
     *enddo
    allsel
     *do,ta,1,tt,1
        *if,ta,eq,1,then
          nsel,s,node,,nodenumber3(ta) 
        *else
         nsel,a,node,,nodenumber3(ta)
        *endif
     *enddo
     ESLN,s,
     SFEDELE,all,4,CONV
    allsel

     *do,ib,1,jj,1
        *if,ib,eq,1,then
          nsel,s,node,,nodenumber(ib) 
        *else
         nsel,a,node,,nodenumber(ib)
         n3=nodenumber(ib)
        *endif
     *enddo
     ESLN,s,

     *get,numelem,elem,0,count
     *get,lenum,elem,0,num,min

     enum=lenum
     nsle,all    
    *do,ii,1,numelem
     emnumber(ii)=enum
     nnumk=nelem(enum,3) 
     nnuml=nelem(enum,4) 
     nnumo=nelem(enum,7) 
     nnump=nelem(enum,8) 
     hfluxl=0
     hfluxk=0
     hfluxp=0
     hfluxo=0
       *do,iii,1,jj
          *if,nnuml,eq,nodenumber(iii),then
              hfluxl=nodehflux(iii)
             *elseif,nnumk,eq,nodenumber(iii)
              hfluxk=nodehflux(iii)
             *elseif,nnump,eq,nodenumber(iii)
              hfluxp=nodehflux(iii)
             *elseif,nnumo,eq,nodenumber(iii)
              hfluxo=nodehflux(iii)
          *endif
       *enddo
       aehflux=(hfluxl+hfluxk+hfluxp+hfluxo)/4
       sfe,enum,4,HFLUX,,hfluxk,hfluxl,hfluxp,hfluxo 

      *get,nexthe,elem,enum,nxth
      enum=nexthe
   *enddo
  allsel
  step3time=step2time+i*dtime          
        time,step3time
        DELTIM,dtime
        KBC,1 
        outres,erase
        outres,BASIC,LAST        
        solve
/solu
    *do,id,1,numelem
     enum=emnumber(id)
     SFEDELE,enum,4,hflux
    *enddo
    *do,ik,1,kk
     bfdele,nodenumber2(ik),HGEN
    *enddo
    nsel,s,loc,y,thick
    SF,all,CONV,15,20
    allsel
*enddo


    nsel,s,loc,y,thick
    SF,all,CONV,15,20
    allsel
*do,hhkk,1,60
step5time=hhkk*0.5+step3time
        time,step5time
        DELTIM,0.5
	outres,erase
        outres,BASIC,LAST 
        solve
*enddo
finish
 
/PREP7  
Antype,trans
! NROPT,UNSYM   
ET,1,SOLID45
mp,ex,1, 68.9e9 
mp,alpx,1,0.000025  
mp,nuxy,1,.33   
MP,DENS,1,2700  
!   
TB,BKIN,1,5               ! Activate a data table   
TBTEMP,0                ! Temperature = 25  
TBDATA,1,280E6,0           ! Yield = 44,000; Tangent modulus = 0
TBTEMP,125  
TBDATA,1,270E6,0
TBTEMP,225  
TBDATA,1,220E6,0
! TBTEMP,500
! TBDATA,1,200E6,0  
! TBTEMP,600
! TBDATA,1,110E6,0  
! TBTEMP,650
! TBDATA,1,75E6,0   
! TBTEMP,700
! TBDATA,1,50E6,0   
TBTEMP,325  
TBDATA,1,70E6,0 
TBTEMP,425  
TBDATA,1,20E6,0 
nsel,all
nsel,s,loc,z,(width-4*smesize),width  
nsel,r,loc,y,0  
d,all,uy,0  
nsel,all
nsel,s,loc,z,0  
dsym,symm,z 
allsel 
finish  
/solu   
NLGEOM,off  
AUTOTS,off  
tref,25 
ldread,temp,1,,,,,rth  ! Read in temperatures from thermal run  
time,0.001  
outres,erase
OUTRES,BASIC,last   
solve   
/solu   
*do,kkjj,2,(dnloct+1),1 
ldread,temp,kkjj,,,,,rth  ! Read in temperatures from thermal run   
*SET,steptime,(kkjj-1)*ddtime+0.001 
time, steptime  
DELTIM,ddtime/10,ddtime/10000,ddtime
outres,erase
OUTRES,BASIC,last   
kbc,0   
solve   
/solu   
*enddo  
*SET,hdnloct,nloct+ndwel-20 
*do,kc,1,hdnloct,1  
*SET,kd,kkjj+kc 
ldread,temp,kd,,,,,rth  ! Read in temperatures from thermal run 
*SET,steptime,dtime+steptime
time, steptime  
DELTIM,dtime/20,dtime/10000,dtime   
outres,erase
OUTRES,BASIC,last   
kbc,0   
solve   
*enddo  
*do,kke,1,20,1  
*SET,kkf,kke+kd 
ldread,temp,kkf,,,,,rth  ! Read in temperatures from thermal run
*SET,steptime,dtime+steptime   
time, steptime  
DELTIM,dtime/50,dtime/10000,ddtime  
outres,erase
OUTRES,BASIC,last   
kbc,0   
solve   
*enddo  
nsel,all
nsel,s,loc,z,(width-4*smesize),width  
nsel,r,loc,y,0  
DDELE,all,all   
allsel  
nsel,s,loc,x,0  
nsel,r,loc,y,thick  
nsel,r,loc,z,width  
d,all,all,0 
allsel  
*do,hhii,1,60   
*SET,step5time,0.5*hhii+steptime
*SET,kh,kkf+hhii 
ldread,temp,kh,,,,,rth  ! Read in temperatures from thermal run 
time,step5time  
DELTIM,0.002,0.001,5 
outres,erase
OUTRES,BASIC,last   
kbc,0   
solve   
/solu   
*enddo  
finish  
save


